//
//  MyAboutSettingVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/7/1.
//

#import "MyAboutSettingVC.h"
#import "My_editTableViewCell.h"
#import "AgreementViewController.h"

@interface MyAboutSettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic)UITableView * aboutTableView;
@property (strong,nonatomic)NSArray * listArr;

@end

@implementation MyAboutSettingVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"关于APP";
    UIImageView * myLogo = [[UIImageView alloc]init];
    myLogo.image = KImageNamed(@"ico_logo");
    myLogo.layer.cornerRadius = 58;
    myLogo.contentMode = UIViewContentModeScaleAspectFill;
    myLogo.clipsToBounds = YES;
    myLogo.layer.borderWidth = 1.5;
    myLogo.layer.borderColor = UIColor.whiteColor.CGColor;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:myLogo];
    
    self.listArr = [[NSArray alloc]initWithObjects:@"检查更新",@"清理缓存",@"用户协议",@"隐私政策", nil];
    self.aboutTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 200, KScreen_W, KScreen_H-KNav_H-200)];
    self.aboutTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.aboutTableView.backgroundColor = viewback_black;
    self.aboutTableView.delegate = self;
    self.aboutTableView.dataSource = self;
    self.aboutTableView.clipsToBounds = YES;
       UILabel * oldshowSSSSTip3 = [[UILabel alloc]init];
    oldshowSSSSTip3.clipsToBounds = YES;
    oldshowSSSSTip3.text = @"kass显示区";
    oldshowSSSSTip3.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip3.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip3.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip3.hidden = YES;
    [self.view addSubview:oldshowSSSSTip3];
    [self.view addSubview:self.aboutTableView];
    

    [myLogo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(55);
        make.centerX.mas_offset(0);
        make.width.height.mas_offset(116);
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    My_editTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"my_cell"];
    if (cell == nil) {
        cell = [[My_editTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"my_cell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.cell_editBtn.userInteractionEnabled = YES;

    cell.bg.backgroundColor = subviewback_black;
    cell.cell_editBtn.hidden = NO;
    cell.cell_value.hidden = NO;
    cell.cell_editBtn_image.hidden = NO;
    cell.cell_remarks_view.hidden = YES;
    
    cell.cell_title.text = self.listArr[indexPath.row];
    cell.cell_editBtn.tag = indexPath.row;
    [cell.cell_editBtn setTitle:NSLocalizedString(@"", nil) forState:UIControlStateNormal];
    if(indexPath.row == 0){
        if([QZUserInfoModel share].updata != nil){
            cell.cell_value.text = @"有更新";
        }else{
            cell.cell_value.text = @"无更新";
        }
    }else if (indexPath.row == 1){
        NSString *sizeStr = [Tools memerySizeStrWithSize:[Tools userCacheSize]];
        cell.cell_value.text = sizeStr;
    }else{
        cell.cell_value.text = @"";
    }
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        if([QZUserInfoModel share].updata != nil){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:SHAREURL] options:@{} completionHandler:^(BOOL success) {
                
            }];
        }else{
            [YBMsgPop showPop:NSLocalizedString(@"暂无更新", nil)];
        }
        
    }else if (indexPath.row == 1) {
        KWeakSelf
        [self cleanCache:^{
            [weakSelf.aboutTableView reloadData];
            [YBMsgPop showPop:@"缓存清除成功"];
        }];
    }else if (indexPath.row == 2) {
        AgreementViewController * xy = [[AgreementViewController alloc]init];
        xy.url = [QZUserInfoModel share].agr; //@"https://docs.qq.com/doc/p/19945cd532bc0d9a3b8882b46d78c25c7c624562";
        xy.Nav_title = @"用户协议";
        [self.navigationController pushViewController:xy animated:YES];
    }else if (indexPath.row == 3) {
        AgreementViewController * xy = [[AgreementViewController alloc]init];
        xy.url = [QZUserInfoModel share].pri; //@"https://docs.qq.com/doc/p/92365bb913de46bbfabc7cd51656e9cce6f4e4a9";
        xy.Nav_title = @"隐私政策";
        [self.navigationController pushViewController:xy animated:YES];
    }
}
/**
 *  清理缓存
 */
-(void)cleanCache:(void (^)(void))block
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //文件路径
        NSString *directoryPath=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
        
        NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
        
        for (NSString *subPath in subpaths) {
            NSString *filePath = [directoryPath stringByAppendingPathComponent:subPath];
            [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
        }
        //返回主线程
        dispatch_async(dispatch_get_main_queue(), ^{
            block();
        });
    });
    
}
@end
